package backpage.controller;

import backpage.common.Result;
import backpage.entity.SalaryLevel;
import backpage.service.SalaryLevelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/salary/levels")
@RequiredArgsConstructor
public class SalaryLevelController {
    private final SalaryLevelService salaryLevelService;

    @GetMapping
    public Result<List<SalaryLevel>> getAllSalaryLevels() {
        return Result.success(salaryLevelService.getAllSalaryLevels());
    }

    @GetMapping("/{id}")
    public Result<SalaryLevel> getSalaryLevelById(@PathVariable Integer id) {
        return Result.success(salaryLevelService.getSalaryLevelById(id));
    }



    @PutMapping("/{id}")
    public Result<Void> updateSalaryLevel(@PathVariable Integer id, @Valid @RequestBody SalaryLevel salaryLevel) {
        salaryLevel.setSalaryLevelId(id);
        salaryLevelService.updateSalaryLevel(salaryLevel);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteSalaryLevel(@PathVariable Integer id) {
        salaryLevelService.deleteSalaryLevel(id);
        return Result.success();
    }
}